<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:50:"/data/web/truckedit/app/home/view/login/index.html";i:1713314073;}*/ ?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>用户登录</title>
	<link href="__STATIC__/css/common.css" rel="stylesheet">
	<link rel="stylesheet" href="__STATIC__/css/index.css">
</head>
<body ms-controller="view">
	<div class="login-main">
		<div class="form-box">
			<select class="login-item" id="" style="height:30px;" ms-duplex="houseId">
				<option value="">请选择磅房</option>
				<option ms-repeat-el="houseList" ms-attr-value="el.houseId">(|el.houseName|)</option>
			</select>
			<select class="login-item" style="height:30px;" ms-duplex="userName">
				<option value="">请选择用户名</option>
				<option ms-repeat-el="userList" ms-attr-value="el.userName">(|el.userName|)</option>
			</select>
			<input type="password" class="login-item" placeholder="密码" style="height:30px;" ms-duplex="userPwd" />
			<button id="submit" style="width:100px;height:40px;background-color:#44B549;color:white;border:1px solid #44B549;border-radius:5px;margin-top:30px;" ms-click="signin">登  录</button>
		</div>
	</div>
	<script src="__STATIC__/js/jquery.min.js"></script>
	<script src="__STATIC__/js/layer/layer.js"></script>
	<script src="__STATIC__/js/avalon.js"></script>
	<script src="__STATIC__/js/common.js"></script>
	<script src="__STATIC__/js/jQuery.md5.js"></script>
	<script src="__STATIC__/js/jquery.cookie.min.js"></script>
	<script src="__STATIC__/js/logic.js"></script>
	<script src="__STATIC__/js/validator.js"></script>
	<script>
		jQuery(document).ready(function(){
			var house = <?=json_encode($houseList)?>;
			logic_house.read();

			avalon.config({
	          interpolate : ["(|","|)"]
	        });

	        var vm = avalon.define({
	        	$id:'view',
	        	houseId:'',
	        	houseList:house,
	        	userName:'',
	        	userPwd:'',
	        	userList:[],
	        	error:false,
	        	msg:'',
	        	load:function(){
	        		console.log(logic_house);
	        		for(var i=0;i<vm.houseList.length;i++){
	        			if(vm.houseList[i]['houseId'] == logic_house.houseId){
	        				vm.houseId = logic_house.houseId;
	        				break;
	        			}
	        		}
	        		TX.msg('正在加载用户列表,请稍后...',{time:20000});
	        		$.post(logic_urls.getAllUserList,{},
	        			function(data){
	        				var json = TX.toJson(data);
	        				if(json.status == 1){
	        					layer.closeAll();
	        					vm.userList = json.data;
	        					avalon.scan();
	        				}else{
	        					TX.msg('加载用户列表失败,请刷新后再试!',{time:5000});
	        				}
	        			}
	        		)
	        		avalon.scan();
	        	},
	        	signin:function(){
	        		var pd = {
	        			houseId:vm.houseId,
	        			userName:vm.userName,
	        			userPwd:$.md5(vm.userPwd + $.md5(vm.userPwd))
	        		};
	        		vm.preCheck();
	        		if(vm.error){
	        			TX.msg(vm.msg,{icon:2});
	        			return;
	        		}
	        		$.post(logic_urls.login,pd,
	        			function(data){
	        				var json = TX.toJson(data);
	        				console.log(json);
	        				if(json.status == 1){
	        					json.data.is_sign_in = true;
	        					logic_user.onSignin(json.data);
	        					logic_house.houseId = json.config['houseId'];
	        					logic_house.save();
	        					window.location.href="<?php echo Url('home/index/index'); ?>";
	        				}else{
	        					TX.msg(json.msg,{icon:1,time:2000});
	        				}
	        			}
	        		);
	        	},
	        	preCheck:function(){
	        		vm.error = false;
	        		vm.msg = validator.checkNumber(vm.houseId,'磅房选择');
	        		if(vm.msg != ''){
	        			vm.error = true;
	        			return;
	        		}
	        		vm.msg = validator.checkText(vm.userName,1,20,'用户名');
	        		if(vm.msg != ''){
	        			vm.error = true;
	        			return;
	        		}
	        		vm.msg = validator.checkPassword(vm.userPwd,'密码');
	        		if(vm.msg != ""){
	        			vm.error = true;
	        			return;
	        		}
	        	}
	        });
	        vm.load();

	        $('body').keypress(function(e){
				if(e.which == 13){
					vm.signin();
				}
			});
		});
		
		

	</script>
	<!--[if lt IE 9]>
	    <script src="__STATIC__/js/respond.js"></script>
	    <script src="__STATIC__/js/html5shiv.js"></script>
	    <script src="__STATIC__/js/placeholder-IE-fixes.js"></script>
	<![endif]-->
</body>
</html>